﻿using System;
using System.Web.Routing;
using Isis.Handlers;

namespace Sample.Web.NonMVC
{
    public class Global : System.Web.HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
            AddApplicationValuesForTestingPurposes();
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            var isisHandler = new IsisRoutingHandler();
            routes.Add(new Route("isis", isisHandler));
            routes.Add(new Route("isis/{controller}", isisHandler));
            routes.Add(new Route("isis/{controller}/{action}", isisHandler));
            routes.Add(new Route("isis/{controller}/{action}/{parameter}", isisHandler));

            //routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapPageRoute(
            //    "Default",                                              // Route name
            //    "{controller}/{action}/{id}",                           // URL with parameters
            //    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            //);
        }

        private void AddApplicationValuesForTestingPurposes()
        {
            Application["StartTime (DateTime)"] = DateTime.Now;
            Application["Name (String)"] = "Isis Sample";
            Application["Meaning Of Life, The Universe, and Everything (int)"] = 42;
            Application["Complex Data Type (Routes)"] = RouteTable.Routes;

        }
    }
}
